home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / source / rpg_scrl / test.pas < prev    next >
Pascal/Delphi Source File  |  1994-09-20  |  24KB  |  764 lines

  1. program test;
  2.  
  3. uses crt;
  4.  
  5. const
  6.      TileHeight = 32;  TileWidth = 32;
  7.  
  8.      BufWidth = 9*TileWidth;  BufDestWidth = 7*TileWidth;
  9.      BufHeight= 7*TileHeight; BufDestHeight= 5*TileHeight;
  10.  
  11.      BufSize  = BufWidth*BufHeight;
  12.  
  13.      (* Pointer to beggining of VGA memory *)
  14.      SCREEN_OFFSET      = $0A000;
  15.  
  16.      StartingTX = 1;
  17.      StartingTY = 4;
  18.  
  19.      (* Tile Constants *)
  20.      Grass   =  1;
  21.      White   =  2;
  22.      Water   = 80;
  23.      Hero1   = 121;
  24.      Hero2   = 122;
  25.      Hero3   = 123;
  26. type
  27.     icon32 = array [1..32,1..32] of byte;
  28.     bufptr = ^buffertype;
  29.     buffertype = array [1..BufSize] of byte;
  30.     MapPtr     = ^MapType;
  31.     MapType    = array [1..20,1..20] of byte;
  32. var
  33.    buffer   : bufptr;
  34.    HeroPic  : icon32;
  35.    Hero2Pic,Hero3Pic : icon32;
  36.    whitepic : icon32;
  37.    grassPic : icon32;
  38.    Water1Pic,Water2Pic : icon32;
  39.    MapTX,MapTY : word;
  40.    ch        : char;
  41.    xo,yo     : integer;  (* x and y offset *)
  42.    Map       : MapPtr;
  43.    tick      : byte;
  44.    ScrollVal : byte;
  45.  
  46.  
  47. Procedure CloseUp; forward;
  48. procedure CopyBufferToScreen (PixelX,PixelY:word); forward;
  49. Procedure DrawWater (tick : byte); forward;
  50. Procedure Init; forward;
  51. Procedure LoadTile (sFileName : string; var Tile : icon32); forward;
  52. Procedure PlaceTileInBuffer (PixelX,PixelY:word; var Pic:icon32); forward;
  53. Procedure PlaceTileOnScreen (PixelX,PixelY:word; Pic:icon32); forward;
  54. Procedure PutDummyDataInMap; forward;
  55. Procedure PutHeroPic; forward;
  56. Procedure PutPic (TileX,TileY : word; Pic : byte); forward;
  57. Procedure PutPicTrans (TileX,TileY : word; Pic : byte); forward;
  58. Procedure SetBG; forward;
  59. Procedure ShowBuffer; forward;
  60. Procedure TestStuff; forward;
  61. Procedure UpdateAnimTiles; forward;
  62. Procedure Walk; forward;
  63.  
  64.  
  65. (**********************************************************************)
  66. (* Assumes buffer is 320x200 *)
  67. procedure CheckBuffer; assembler;
  68. label
  69.   l1, l2;
  70.   Asm
  71.      (* Wait for Vertical Retrace *)
  72.      cli
  73.      mov dx,3DAh
  74. l1:
  75.      in al,dx
  76.      and al,08h
  77.      jnz l1
  78. l2:
  79.      in al,dx
  80.      and al,08h
  81.      jz  l2
  82.      sti
  83.      (* End Check for Retrace *)
  84.  
  85.      push ds
  86.      push es
  87.  
  88.      lds si,Buffer;   (* load scratch page  *)
  89.      mov ax,Screen_Offset;  (* load screen coords *)
  90.      mov es,ax
  91.      xor di,di
  92.      mov cx,32000
  93.      rep movsw
  94.  
  95.      pop es
  96.      pop ds
  97.  End;
  98. (**********************************************************************)
  99. Procedure CloseUp;
  100.   Begin
  101.        dispose (buffer);
  102.        dispose (Map);
  103.        asm
  104.           mov ax,3
  105.           int 10h
  106.        end;
  107.        writeln ('Thank you for running this demo');
  108.   End;
  109. (**********************************************************************)
  110. (* Copies whole screen - buffer is not length of screen so must do    *)
  111. (* in rows. One big sprite copy routine, really                       *)
  112. (**********************************************************************)
  113. procedure CopyBufferToScreen (PixelX,PixelY:word); assembler;
  114.  const
  115.       NumWordsLong = BufDestWidth div 2;
  116.   Asm
  117.      (* start real code - preserve data and extra segments *)
  118.      push ds                 (* preserve segments *)
  119.      push es
  120.  
  121.      (* Copy from where? *)
  122.      lds  si,Buffer          (* point to start of buffer *)
  123.  
  124.      mov  ax,BufWidth        (* and figure offset *)
  125.      mul  PixelY
  126.      add  ax,PixelX
  127.      mov  si,ax
  128.  
  129.  
  130.      (* Copy to where? *)
  131.      mov  ax,Screen_Offset;  (* load screen coords *)
  132.      mov  es,ax              (* load es from ax *)
  133.      xor  di,di              (* make di = 0 *)
  134.  
  135.      (* Offset from top of screen *)
  136.      mov  ax,320
  137.      mov  PixelX,22   (* pixels from top *)
  138.      mul  PixelX
  139.      add  ax,45       (* pixels from left *)
  140.      mov  di,ax
  141.  
  142.      (* Wait for Vertical Retrace *)
  143.      cli            (* clear interrupt *)
  144.      mov  dx,3DAh   (* port and sequencer stuff *)
  145.   @@l1:
  146.      in   al,dx
  147.      and  al,08h
  148.      jnz  @@l1
  149.   @@l2:
  150.      in   al,dx
  151.      and  al,08h
  152.      jz   @@l2
  153.      sti            (* restore interrupt *)
  154.      (* End Check for Retrace *)
  155.  
  156.  
  157.      (* Copy Data *)
  158.      mov  bx,BufDestHeight
  159.   @@CopyRowLoop:
  160.      mov  cx,NumWordsLong    (* how many words long is the row? *)
  161.      push di                 (* save offset *)
  162.      push si
  163.      rep  movsw              (* copy cx words to the buffer *)
  164.      pop  si
  165.      add  si,BufWidth
  166.      pop  di                 (* restore offset *)
  167.      add  di,320        (* go to next line *)
  168.      dec  bx                 (* finished that row already *)
  169.      jnz  @@CopyRowLoop      (* if there are any more rows in bx *)
  170.                              (* go ahead and do this again *)
  171.  
  172.  
  173.      (* ok, we can quit now *)
  174.      pop es
  175.      pop ds
  176.   End;
  177. (**********************************************************************)
  178. Procedure DrawWater (tick : byte);
  179.   Begin
  180.        if (tick=1) then
  181.           begin
  182.                PutPic (MapTX+3,MapTY,Water);
  183.                PutPic (MapTX+3,MapTY+1,Water);
  184.                PutPic (MapTX+2,MapTY+2,Water);
  185.                PutPic (MapTX+2,MapTY+3,Water);
  186.                PutPic (MapTX+3,MapTY+4,Water);
  187.                PutPic (MapTX+3,MapTY+5,Water);
  188.           end
  189.        else
  190.            begin
  191.                 PutPic (MapTX+3,MapTY,Water);
  192.                 PutPic (MapTX+3,MapTY+1,Water);
  193.                 PutPic (MapTX+2,MapTY+2,Water);
  194.                 PutPic (MapTX+2,MapTY+3,Water);
  195.                 PutPic (MapTX+3,MapTY+4,Water);
  196.                 PutPic (MapTX+3,MapTY+5,Water);
  197.            end;
  198.   End;
  199. (**********************************************************************)
  200. Procedure Init;
  201.  var
  202.     code : integer;
  203.   Begin
  204.        (* Set scroll increment *)
  205.        if ParamCount > 0 then
  206.           begin
  207.                if paramstr(1) = '?' then
  208.                   begin
  209.                        writeln ('Usage: Scroll.exe [1/2/4/8/16/32]');
  210.                        halt(0);
  211.                   end;
  212.                val(paramstr(1),ScrollVal,code);
  213.                if code <> 0 then
  214.                   begin
  215.                        writeln('that''s not a valid argument');
  216.                        writeln('Usage: Scroll [1-32]');
  217.                        halt(0);
  218.                   end
  219.                else
  220.                    begin
  221.                         if (ScrollVal<1) or (ScrollVal>32) then
  222.                            begin
  223.                                 writeln('that''s not a valid argument');
  224.                                 writeln('Usage: Scroll [1-32]');
  225.                                 halt(0);
  226.                            end;
  227.                    end;
  228.           end
  229.        else
  230.            ScrollVal:=4;
  231.  
  232.        Tick := 1;
  233.  
  234.        LoadTile ('hero1.til',HeroPic);
  235.        LoadTile ('hero2.til',Hero2Pic);
  236.        LoadTile ('hero3.til',Hero3Pic);
  237.        LoadTile ('grass.til',GrassPic);
  238.        LoadTile ('water1.til',Water1Pic);
  239.        LoadTile ('water2.til',Water2Pic);
  240.  
  241.        repeat
  242.              new (buffer);
  243.              if ofs (buffer^) <> 0 then begin
  244.                 dispose (buffer);
  245.                 (* new (buffer); *)
  246.              end;
  247.        until ofs (buffer^) = 0;
  248.  
  249.  
  250.        fillchar (buffer^,BufSize,#0);
  251.  
  252.        PutDummyDataInMap;
  253.  
  254.        asm
  255.           mov ax,13h
  256.           int 10h
  257.        end;
  258.  
  259.        (* MapTX - Top Visible tile *)
  260.        MapTX:=1; MapTY:=1;
  261.        XO:=0; YO:=0;
  262.   End;
  263. (**********************************************************************)
  264. Procedure LoadTile (sFileName : string; var Tile : icon32);
  265.  var
  266.     x,y,sPixel     : byte;
  267.     fIconFile      : file of byte;
  268.   Begin
  269.        (* Open the File *)
  270.        assign (fIconFile,sFileName);
  271.        {$I-}reset(fIconFile);{$I+}
  272.        if (IOResult <> 0) then
  273.           begin
  274.                writeln ('The file ',sFileName,' was not found');
  275.                halt;
  276.           end;
  277.  
  278.        (* Read from the file *)
  279.        for y:=1 to 32 do
  280.            for x:=1 to 32 do
  281.                begin
  282.                     read(fIconFile,sPixel);
  283.                     Tile[y,x]:=sPixel;
  284.                end;
  285.  
  286.        (* Close the file *)
  287.        close (fIconFile);
  288.   End;
  289. (**********************************************************************)
  290. Procedure PlaceTileOnScreen (PixelX,PixelY:word; Pic:icon32); assembler;
  291.   const
  292.        WordLength = TileWidth div 2;
  293.    Asm
  294.         (* figure pixel offset onto screen *)
  295.         mov  ax,320
  296.         mul  PixelY
  297.         add  ax,PixelX          (* gives (Y*width)+x *)
  298.  
  299.         (* preserve data segment pointer *)
  300.         mov  dx,ds
  301.  
  302.         (* Copy to where? *)
  303.         mov  di,ax
  304.         mov  ax,Screen_Offset
  305.         mov  es,ax
  306.  
  307.         (* Copy from where? *)
  308.         lds  si,Pic
  309.  
  310.         (* Copy Data *)
  311.         mov  bx,TileHeight
  312.    @@CopyRowLoop:
  313.         mov  cx,WordLength      (* how many words long is the row? *)
  314.         push di                 (* save offset *)
  315.         rep  movsw              (* copy cx words to the buffer *)
  316.         pop  di                 (* restore offset *)
  317.         add  di,320        (* go to next line *)
  318.         dec  bx                 (* finished that row already *)
  319.         jnz  @@CopyRowLoop      (* if there are any more rows in bx *)
  320.                                 (* go ahead and do this again *)
  321.  
  322.         (* OK, all done, so quit *)
  323.         mov  ds,dx              (* restore data segment pointer *)
  324.    End;
  325. (**********************************************************************)
  326. Procedure PlaceTileOnScreenTrans (PixelX,PixelY:word; var Pic:icon32); assembler;
  327.   const
  328.        WordLength = TileWidth div 2;
  329.    Asm
  330.         (* figure pixel offset onto screen *)
  331.         mov  ax,320
  332.         mul  PixelY
  333.         add  ax,PixelX          (* gives (Y*width)+x *)
  334.  
  335.         (* preserve data segment pointer *)
  336.         push ds
  337.         push es
  338.  
  339.         (* Copy to where? *)
  340.         mov  di,ax
  341.         mov  ax,Screen_Offset
  342.         mov  es,ax
  343.  
  344.         (* Copy from where? *)
  345.         lds  si,Pic
  346.  
  347.         (* Copy Data - Skip Pixels color 0 (black) *)
  348.         mov  bx,TileHeight
  349.    @@CopyRowLoop:
  350.         mov  cx,TileWidth       (* how many words long is the row? *)
  351.         push di                 (* save offset *)
  352.         (*push si*)
  353.    @@PutPixel:
  354.        (* xor  ax,ax*)              (* clear ax - we're gonna use it *)
  355.        (* cmp  0,[ds:si] *)
  356.         mov  ax,[ds:si]
  357.         cmp  ax,0               (* is this a black (#0) pixel?    *)
  358.         je   @@SkipPixel        (* if so, skip it (goto SkipPixel *)
  359.         movsb                   (* copy cx words to the buffer    *)
  360.         loop @@PutPixel         (* keep looping until cx=0        *)
  361.  
  362.         (* Move to Next Row *)
  363.         (* pop  si
  364.            add  si,320 *)
  365.    @@EndOfRow:
  366.         pop  di                 (* restore offset *)
  367.         add  di,320             (* go to next line *)
  368.         dec  bx                 (* finished that row already *)
  369.         jnz  @@CopyRowLoop      (* if there are any more rows in bx *)
  370.                                 (* go ahead and do this again *)
  371.         jmp @@Done
  372.  
  373.    @@SkipPixel:
  374.         inc di
  375.         inc si
  376.         dec cx
  377.         cmp cx,0           (* are we at the end of the row? *)
  378.         je  @@EndOfRow     (* if so, go to end of row line  *)
  379.         jmp @@PutPixel     (* otherwise, do the next pixel  *)
  380.  
  381.  
  382.         (* OK, all done, so quit *)
  383.    @@Done:
  384.         pop  es
  385.         pop  ds
  386.    End;
  387. (**********************************************************************)
  388. Procedure PlaceTileInBuffer (PixelX,PixelY:word; var Pic:icon32); assembler;
  389.   const
  390.        WordLength = TileWidth div 2;
  391.    Asm
  392.         (* figure pixel offset in buffer *)
  393.         mov  ax,BufWidth
  394.         mul  PixelY
  395.         add  ax,PixelX          (* gives (Y*width)+x *)
  396.  
  397.         (* preserve data segment pointer *)
  398.         mov  dx,ds
  399.  
  400.         (* Copy to where? *)
  401.         les  di,buffer
  402.         mov  di,ax
  403.  
  404.         (* Copy from where? *)
  405.         lds  si,Pic
  406.  
  407.         (* Copy Data *)
  408.         mov  bx,TileHeight
  409.    @@CopyRowLoop:
  410.         mov  cx,WordLength      (* how many words long is the row? *)
  411.         push di                 (* save offset *)
  412.         rep  movsw              (* copy cx words to the buffer *)
  413.         pop  di                 (* restore offset *)
  414.         add  di,BufWidth        (* go to next line *)
  415.         dec  bx                 (* finished that row already *)
  416.         jnz  @@CopyRowLoop      (* if there are any more rows in bx *)
  417.                                 (* go ahead and do this again *)
  418.  
  419.         (* OK, all done, so quit *)
  420.         mov  ds,dx              (* restore data segment pointer *)
  421.    End;
  422. (**********************************************************************)
  423. Procedure PlaceTileInBufferTrans (PixelX,PixelY:word; var Pic:icon32); assembler;
  424.   const
  425.        WordLength = TileWidth div 2;
  426.    Asm
  427.         (* figure pixel offset in buffer *)
  428.         mov   ax,BufWidth
  429.         mul   PixelY
  430.         add   ax,PixelX          (* gives (Y*width)+x *)
  431.  
  432.         (* preserve data segment pointer *)
  433.         push  es
  434.         push  ds
  435.  
  436.         (* Copy to where? *)
  437.         les   di,buffer
  438.         mov   di,ax
  439.  
  440.         (* Copy from where? *)
  441.         lds   si,Pic
  442.  
  443.         (* Copy Data - Don't draw black (color 0) pixels *)
  444.         mov   bx,TileHeight
  445.    @@CopyRowLoop:
  446.         mov   cx,TileWidth       (* how many words long is the row? *)
  447.         push  di                 (* save offset *)
  448.    @@PutPixel:
  449.         mov   ax,[ds:si]
  450.         cmp   ax,0               (* is this a black (#0) pixel?    *)
  451.         je    @@SkipPixel        (* if so, skip it (goto SkipPixel *)
  452.         movsb                    (* copy cx words to the buffer    *)
  453.         loop  @@PutPixel         (* keep looping until cx=0        *)
  454.  
  455.         (* Move to Next Row *)
  456.    @@EndOfRow:
  457.         pop   di                 (* restore offset *)
  458.         add   di,BufWidth        (* go to next line *)
  459.         dec   bx                 (* finished that row already *)
  460.         jnz   @@CopyRowLoop      (* if there are any more rows in bx *)
  461.                                  (* go ahead and do this again *)
  462.         jmp   @@Done
  463.  
  464.    @@SkipPixel:
  465.         inc   di
  466.         inc   si
  467.         dec   cx
  468.         cmp   cx,0           (* are we at the end of the row? *)
  469.         je    @@EndOfRow     (* if so, go to end of row line  *)
  470.         jmp   @@PutPixel     (* otherwise, do the next pixel  *)
  471.  
  472.         (* OK, all done, so quit *)
  473.    @@Done:
  474.         pop   ds              (* restore data segment pointer *)
  475.         pop   es
  476.    End;
  477.  
  478. (**********************************************************************)
  479. Procedure PutDummyDataInMap;
  480.  var
  481.     x,y : byte;
  482.   Begin
  483.        new (Map);
  484.  
  485.        for y:=1 to 20 do
  486.            for x:=1 to 20 do
  487.                Map^[x,y]:=Grass;
  488.  
  489.        (* add a river *)
  490.        Map^[4,1]:=Water;
  491.        Map^[3,1]:=Water;
  492.        Map^[4,2]:=Water;
  493.        Map^[4,3]:=Water;
  494.        Map^[3,3]:=Water;
  495.        Map^[3,4]:=Water;
  496.        Map^[3,5]:=Water;
  497.        Map^[4,5]:=Water;
  498.        Map^[4,6]:=Water;
  499.        Map^[4,7]:=Water;
  500.        Map^[3,7]:=Water;
  501.        Map^[3,8]:=Water;
  502.        Map^[3,9]:=Water;
  503.        Map^[4,9]:=Water;
  504.  
  505.        Map^[4,10]:=Water;
  506.        Map^[4,11]:=Water;
  507.        Map^[3,11]:=Water;
  508.        Map^[3,12]:=Water;
  509.        Map^[3,13]:=Water;
  510.        Map^[4,13]:=Water;
  511.        Map^[4,14]:=Water;
  512.        Map^[4,15]:=Water;
  513.        Map^[3,15]:=Water;
  514.        Map^[3,16]:=Water;
  515.        Map^[3,17]:=Water;
  516.        Map^[4,17]:=Water;
  517.        Map^[4,18]:=Water;
  518.        Map^[4,19]:=Water;
  519.        Map^[3,19]:=Water;
  520.        Map^[3,20]:=Water;
  521. (*
  522.        Map^[4,10]:=Water;
  523.        Map^[3,10]:=Water;
  524.        Map^[3,11]:=Water;
  525.        Map^[3,12]:=Water;
  526.        Map^[4,12]:=Water;
  527.        Map^[5,12]:=Water;
  528.        Map^[5,13]:=Water;
  529.        Map^[5,14]:=Water;
  530.        Map^[5,15]:=Water;
  531.        Map^[4,16]:=Water;
  532.        Map^[4,17]:=Water;
  533.        Map^[4,18]:=Water;
  534.        Map^[4,19]:=Water;
  535.        Map^[3,19]:=Water;
  536.        Map^[3,20]:=Water;
  537.        Map^[2,20]:=Water;
  538.  
  539. *)
  540.   End;
  541. (**********************************************************************)
  542. Procedure PutHeroPic;
  543. (* Hero should go in the center - 4,3 (0 is first) plus any *)
  544. (* changes in offset *)
  545.  var
  546.     PixelX,PixelY : word;
  547.   Begin
  548.         (* Convert World Tile Coords to Pixel in Buffer *)
  549.         PixelX:=4*TileWidth; PixelY:=3*TileHeight;
  550.         PixelX:=PixelX+XO;   PixelY:=PixelY+YO;
  551.  
  552.         (* copy the data into the buffer *)
  553.         (* PlaceTileInBuffer (pixelx,pixely,HeroPic); *)
  554.         PlaceTileInBufferTrans (PixelX,PixelY,HeroPic);
  555.   End;
  556. (**********************************************************************)
  557. Procedure PutPic (TileX,TileY : word; Pic : byte);
  558. (* Tile 0 = first tile (the buffer's border)           *)
  559. (* Tile 1 = first tile visible to map                  *)
  560. (* MapTX  = Top Left Buffer Border Tile.               *)
  561. (* Tile's are world Coordinates, not buffer coords     *)
  562. (* Should never get a TileX/Y or MapTX/Y under 0       *)
  563.  var
  564.     PixelX,PixelY : word;
  565.   Begin
  566.         (* Convert World Tile Coords to Pixel in Buffer *)
  567.         (* Figure Where tile goes in relation to Top Left Tile *)
  568.         PixelX:=TileX-MapTX;
  569.         PixelY:=TileY-MapTY;
  570.  
  571.         (* and multiply by tile width *)
  572.         PixelX:=PixelX*TileWidth;
  573.         PixelY:=PixelY*TileHeight; (* same as shl 5 *)
  574.  
  575.         (* copy data into the buffer *)
  576.         case Pic of
  577.                  Grass   : PlaceTileInBuffer (pixelx,pixely,GrassPic);
  578.                  White   : PlaceTileInBuffer (pixelx,pixely,WhitePic);
  579.                  Water   : begin
  580.                                 if tick = 0 then
  581.                                    PlaceTileInBuffer (pixelx,pixely,Water1Pic)
  582.                                 else
  583.                                     PlaceTileInBuffer (pixelx,pixely,Water2Pic);
  584.                            end;
  585.                  Hero1   : PlaceTileInBuffer (pixelx,pixely,HeroPic);
  586.                  Hero2   : PlaceTileInBuffer (pixelx,pixely,Hero2Pic);
  587.                  Hero3   : PlaceTileInBuffer (pixelx,pixely,Hero3Pic);
  588.         end; (* case *)
  589.   End;
  590. (**********************************************************************)
  591. Procedure PutPicTrans (TileX,TileY : word; Pic : byte);
  592.  var
  593.     PixelX,PixelY : word;
  594.   Begin
  595.         (* Convert World Tile Coords to Pixel in Buffer *)
  596.         (* Figure Where tile goes in relation to Top Left Tile *)
  597.         PixelX:=TileX-MapTX;
  598.         PixelY:=TileY-MapTY;
  599.  
  600.         (* and multiply by tile width *)
  601.         PixelX:=PixelX*TileWidth;
  602.         PixelY:=PixelY*TileHeight; (* same as shl 5 *)
  603.  
  604.         (* and check for scrolling - move offset *)
  605.         PixelX:=PixelX+XO;
  606.         PixelY:=PixelY+YO;
  607.  
  608.         (* copy data into the buffer *)
  609.         case Pic of
  610.                  Grass   : PlaceTileInBufferTrans (pixelx,pixely,GrassPic);
  611.                  White   : PlaceTileInBufferTrans (pixelx,pixely,WhitePic);
  612.                  Water   : begin
  613.                                 if tick = 0 then
  614.                                    PlaceTileInBufferTrans (pixelx,pixely,Water1Pic)
  615.                                 else
  616.                                     PlaceTileInBufferTrans (pixelx,pixely,Water2Pic);
  617.                            end;
  618.                  Hero1   : PlaceTileInBufferTrans (pixelx,pixely,HeroPic);
  619.                  Hero2   : PlaceTileInBufferTrans (pixelx,pixely,Hero2Pic);
  620.                  Hero3   : PlaceTileInBufferTrans (pixelx,pixely,Hero3Pic);
  621.         end; (* case *)
  622.   End;
  623.  
  624. (**********************************************************************)
  625. Procedure SetBG;
  626.  var
  627.     x,y : byte;
  628.   Begin
  629.        for y:= MapTY to MapTY+6 do
  630.            for x:=MapTX to MapTX+8 do
  631.                PutPic (x,y,Map^[x,y]);
  632.   End;
  633. (**********************************************************************)
  634. Procedure ShowBuffer;
  635.  var
  636.     PixelX,PixelY : word;
  637.   Begin
  638.        (* Update any Animated Tiles *)
  639.        UpdateAnimTiles;
  640.  
  641.        (* Copy center squares, ignore the 1 tile buffer *)
  642.        PixelX:=TileWidth; (* skip the first tile (the border) *)
  643.        PixelY:=TileHeight;
  644.  
  645.        (* now adjust for scrolling *)
  646.        PixelX:=PixelX+XO;
  647.        PixelY:=PixelY+YO;
  648.  
  649.        (* copy the data to the screen *)
  650.        CopyBufferToScreen (PixelX,PixelY);
  651.   End;
  652. (**********************************************************************)
  653. Procedure TestStuff;
  654.  const
  655.       WS = 1000;
  656.  var
  657.     x,y : byte;
  658.   Begin
  659.        (* Top Visible Corner is MapTX+1 MapTY+1 *)
  660.        MapTX:=StartingTX;  MapTY:=StartingTY;
  661.  
  662.        SetBG;
  663.  
  664.        repeat
  665.              Walk;
  666.        until keypressed;
  667.  
  668. (*       Walk; *)
  669.        ch:=readkey; (* clear buffer *)
  670.   End;
  671. (**********************************************************************)
  672. Procedure UpdateAnimTiles;
  673.  var
  674.     x,y : byte;
  675.   Begin
  676.        (* Search through the map and update any animated tiles *)
  677.        for y:= MapTY to MapTY+6 do
  678.            for x:=MapTX to MapTX+8 do
  679.                if (Map^[x,y]>79) and (Map^[MapTX,MapTY]<121) then
  680.                   PutPic(x,y,Map^[x,y]);
  681.  
  682.        (* Update master tick *)
  683.        if tick=0 then tick:=1 else tick:=0;
  684.   End;
  685. (**********************************************************************)
  686. Procedure Walk;
  687.  const
  688.       WS = 400;
  689.       NumPixels = -32; (* number of pixels to walk *)
  690.       NumTiles  = StartingTY;
  691.  var
  692.     OldY : integer;
  693.     tick : byte;
  694.     walktick : byte;
  695.     TilesWalked : byte;
  696.     Step        : byte;
  697.   Begin
  698.        YO:=0;
  699.        OldY:=YO;
  700.        tick:=1;
  701.        walktick := 1;
  702.        TilesWalked:=0;
  703.        Step:=ScrollVal;
  704.  
  705.        MapTX:=StartingTX;  MapTY:=StartingTY;
  706.        SetBG;
  707.  
  708.        repeat
  709.              (* Center square is MapTX+4, MapTY+3 *)
  710.              (* Next square up is MapTX+4, MapTY+2 *)
  711.  
  712.              (* erase old image *)
  713.              putpic      (MapTX+4,MapTY+3,Map^[MapTX+4,MapTY+3]);
  714.              putpic      (MapTX+4,MapTY+2,Map^[MapTX+4,MapTY+2]);
  715.  
  716.              (* move foward 4 spaces *)
  717.              dec(YO,Step);
  718.  
  719.              (* draw new position *)
  720.              case WalkTick of
  721.                   0,2 : PutPicTrans (MapTX+4,MapTY+3,Hero1);
  722.                   1   : PutPicTrans (MapTX+4,MapTY+3,Hero2);
  723.                   3   : PutPicTrans (MapTX+4,MapTY+3,Hero3);
  724.              end;
  725.              inc(walktick);
  726.              if walktick=4 then walktick:=0;
  727.  
  728.              (* show screen *)
  729.              ShowBuffer;
  730.  
  731.              (* and wait a bit *)
  732.              delay (WS);
  733.  
  734.              if (YO <= -32) then
  735.                 begin
  736.                      inc(TilesWalked);
  737.                      YO:=0;
  738.                      dec(MapTY);
  739.                      SetBG;
  740.                 end;
  741.        until (TilesWalked=NumTiles);
  742.  
  743.        (* ok, for the last time erase his old position *)
  744.        putpic (MapTX+4,MapTY+3,Map^[MapTX+4,MapTY+3]);
  745.        putpic (MapTX+4,MapTY+2,Map^[MapTX+4,MapTY+3]);
  746.  
  747.        (* Move the map up one and stop the scrolling offset *)
  748.        YO:=0;
  749.        dec(MapTY);
  750.  
  751.        (* Now that the MapTY has changed, we have to draw new tiles *)
  752.        SetBG;
  753.  
  754.        (* Show him in standing position at end *)
  755.        PutPicTrans (MapTX+4,MapTY+3,Hero1);
  756.        ShowBuffer;
  757.   End;
  758. (**********************************************************************)
  759. (**********************************************************************)
  760. BEGIN
  761.      Init;
  762.      TestStuff;
  763.      CloseUp;
  764. END.